package com.qf.service.impl;

import com.qf.bean.Item;
import com.qf.dao.ItemDao;
import com.qf.service.ItemService;
import com.qf.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ItemServiceImpl implements ItemService{

    @Autowired
    private ItemDao itemDao;


    @Override
    public PageInfo<Item> findItemByCondition(String name, Integer page, Integer size) {
        //1.查询数据总条数
        Integer count = itemDao.findCountByNameLike(name);
        //2.创建分页工具类
        PageInfo<Item> pageInfo=new PageInfo(page,size,count);
        //3.查询具体的list(数据库查询到的数据)
        List<Item> list = itemDao.findByNameLikeLimit(name, pageInfo.getOffset(), pageInfo.getSize());
        //4.将查询到的list封装到pageInfo
        pageInfo.setList(list);
        //5.返回pageInfo
        return pageInfo;
    }
}
